<template>
	<view class="main-box">
		<div class="search-box">
			
	 <my-search></my-search>
		</div>
	 <view class="swiper-contain">		
		<swiper :indicator-dots="true" :autoplay="true" 
		:interval="3000" :duration="1000">
			<swiper-item v-for="(item, index) in swiperList" :key="index">
				<navigator class="swiper-item"
					:url="'/subpkg/goods_detail/goods_detail?id='+item.goods_id"
				>
					<image :src="item.image_src" alt=""/>
				</navigator>
			</swiper-item>
		</swiper>
	 </view>
	 
	 <view class="homeCate_contain">
	 	<view class="homeCate_item" v-for="(item, i) in homeCateList" :key="i"
			@click="swichTab(item.name)"
		>
	 		<image :src="item.image_src" mode=""></image>
	 	</view>
	 </view>
	 
	 <view class="floor_contain">
		 <view class="floor_item" v-for="(item, i) in floorList" :key="i">
		 	<image :src="item.floor_title.image_src" mode=""
			class="floor_title"
			></image>
			<view class="floor_list">
				<navigator class="left_img_floor" :url="item.product_list[0].url">
					<image 
					:src="item.product_list[0].image_src" 
					:style="{width: item.product_list[0].image_width + 'rpx'}"
					mode="widthFix"
					></image>
				</navigator>
				<view class="right_img_floor">
					<navigator 
					v-for="(item2, i2) in item.product_list" 
					:key="i2" 
					:url="item2.url"
					v-if="i2 !== 0"
					>
					<image 
					 :src="item2.image_src" 
					 :style="{width: item2.image_width + 'rpx'}"
					 mode="widthFix"></image>
					</navigator>
				</view>
			</view>
		 </view>
	 	
	 </view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		  mixins: [badgeMix],
		data() {
			return {
				swiperList:[],
				homeCateList:[],
				floorList:[]
			};
		},
		onLoad() {
			this.getSwiper(),
			this.getHomeCate(),
			this.getFloorList()
		},
		methods: {
			//获取轮播叛数据
			async getSwiper(){
				const { data: message} = await uni.$http.get('/api/public/v1/home/swiperdata')
				if(message.meta.status !== 200){
					        return uni.$showMsg()
				}
				console.log(message)
				this.swiperList = message.message
			},
		//获取分类数据
		async getHomeCate(){
			const {data: message} = await uni.$http.get('/api/public/v1/home/catitems')
			console.log(message)
			if(message.meta.status !== 200){
				        return uni.showMsg()
			}
			this.homeCateList = message.message
		},
		swichTab(name){
			if(name !== '分类') return 
			uni.switchTab({
				url:'/pages/cate/cate'
			})
		},
		
		//获取楼层数据
		async getFloorList(){
			const {data:message} = await uni.$http.get('/api/public/v1/home/floordata')
			console.log(message)
			if(message.meta.status !== 200) return uni.$showMsg()
			//对floor数据增加导航地址
			message.message.forEach((item) => {
				item.product_list.forEach((i) => {
					i.url = '/subpkg/goods_list/goods_list?' + i.navigator_url.split('?')[1]
				})
			})
			this.floorList = message.message
		}
		}
		
	}
</script>

<style lang="scss">
.search-box{
	position: sticky;
	top: 0;
	z-index: 999;
}
swiper {
 height: 330rpx;

 .swiper-item,
 image {
   width: 100%;
   height: 100%;
 }
}
.homeCate_contain{
	display: flex;
	justify-content: space-around;
	margin: 15px 0;
	.homeCate_item{
	image{
		width: 128rpx;
		height: 140rpx;
	}
}}
.floor_item{
	margin: 15px 0 15px 5px;
.floor_title{
		height: 60rpx;
		width: 100%;
}
.floor_list{
	display: flex;
	.right_img_floor{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
	}
}

}
</style>
